package com.edu.bhu.admin.util;

import com.edu.bhu.admin.domain.BikRecord;
import com.edu.bhu.common.utils.DateUtils;

import java.math.BigDecimal;
import java.util.Date;

import static com.edu.bhu.common.utils.DateUtils.differentHoursByMillisecond;

/**
 * @author heyinan
 *
 * @desc price总价计算工具类
 * @date 2022/3/03
 */
public class priceUtil {

    //赋予bikRecord的price属性
    public static BikRecord totalPrice(BikRecord bikRecord, BigDecimal price)
    {
        //拿到开始时间和结束时间
        Date startTime = bikRecord.getStartTime();
        Date endTime = bikRecord.getEndTime();

        //计算花费的小时数（向上取整）
        int hours = differentHoursByMillisecond(startTime,endTime);

        //计算总价并插入
        BigDecimal totalPrice = price.multiply(BigDecimal.valueOf(hours));
        bikRecord.setPrice(totalPrice);

        return bikRecord;
    }


}
